Fix clang conversion warnings in string_util::split_string_list#1207
Conversation
|
Thanks! I've updated it to keep the signedness of the original, because I'm trying to follow my own advice of using signed sizes/indexes. I'll merge it this way... but if this changed version doesn't resolve the problem, please open a new PR. Again, thanks! |
|
Unfortunately the clang warnings remain. The warnings are emitted in 2 places when a signed integer is supplied to:
Here's a repro showing the warnings with the updated function. I also prefer using signed integer types but they pose an annoying problem with clang when also following the best practice advice to compile with high warning levels! Here's a version that keeps the signed indices and also uses auto split_string_list(std::string_view str)
-> std::vector<std::string_view>
{
std::vector<std::string_view> ret;
auto is_id_char = [](char c) {
return std::isalnum(c) || c == '_';
};
auto pos = decltype(std::ssize(str)){ 0 };
while( pos < std::ssize(str) ) {
// Skip non-alnum
while (pos < std::ssize(str) && !is_id_char(str[static_cast<size_t>(pos)])) {
++pos;
}
auto start = pos;
// Find the end of the current component
while (pos < std::ssize(str) && is_id_char(str[static_cast<size_t>(pos)])) {
++pos;
}
// Add nonempty substring to the vector
if (start < pos) {
ret.emplace_back(str.substr(static_cast<size_t>(start), static_cast<size_t>(pos) - static_cast<size_t>(start)));
}
}
return ret;
} |
Argh. I thought I did this all the time in cppfront though... does Clang trunk also complain about the rest of cppfront at high warning levels? And is there a specific warning here that should be disabled (e.g., I do disable a few noisy ones at the top of common.h)? |
|
|
I created #1212 to hopefully resolve this. |
The
string_util::split_string_listfunction incpp2util.hcauses clang to emit some conversion warnings:Repro here
This PR fixes those warnings by changing the type of
startandpos.